package cn.wolfcode.wolf2w.advice;

import cn.wolfcode.wolf2w.exception.LogicException;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class CommonExceptionHandler {

    @ExceptionHandler(LogicException.class)
    @ResponseBody
    public Object LogicExceptionHandler(Exception e){
        String msg = e.getMessage();
        JsonResult ret = JsonResult.error(JsonResult.CODE_ERROR, msg, null);
        return ret;
    }

    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public Object RuntimeExceptionHandler(){
        JsonResult ret = JsonResult.defaultError();
        return ret;
    }


}
